﻿var verifyApp = angular.module('verifyApp', []);

// create angular controller
verifyApp.controller('VerifyController', function ($scope, $location, VerificationService) {
    $scope.loadContacts = function () {
        VerificationService.getContacts().then(function (contacts) {
            $scope.contacts = contacts;
            $scope.error = "";
        }, function ()
        {
            $scope.error = "Error occured.";
        });
    };

    $scope.sendCode = function () {
        $("#spinner").show();
        $scope.error = "";
        $scope.success = "";
        VerificationService.sendVerificationCode().then(function () {
            $("#spinner").hide();
            $scope.error = "";
            $scope.success = "Verification code sent.";
        }, function () {
            $("#spinner").hide();
            $scope.error = "Error occured.";
        });
    };


    $scope.activateMyAccount = function (code) {
        $("#spinner").show();
        $scope.error = "";
        $scope.success = "";
        VerificationService.activateAccount(code).then(function () {
            $("#spinner").hide();
            $scope.error = "";
            $scope.success = "";
            window.location.assign("/Home");
        }, function () {
            $("#spinner").hide();
            $scope.error = "Wrong verification code.";
        });
    };

});
